'''
@Project ：my_python_project 
@File    ：time.py
@IDE     ：PyCharm 
@Author  ：xionglinhui
@Date    ：2024/9/4 上午8:34 
'''

import time

# time_stamp = time.time()
# print(f'时间戳：{time_stamp}', f'==>类型为{type(time_stamp)}')

# format_time = time.strftime("%Y-%m-%d %H:%M:%S")
# format_time1 = time.strftime("%Y-%m-%d %H:%M:%s")
# format_time2 = time.strftime("%Y-%m-%d %X")
# print(format_time)
# print(format_time1)
# print(format_time2)

# print('本地时区的struct_time:\n{}'.format(time.localtime()))
#
# print('UTC时区的struct_time:\n{}'.format(time.gmtime()))
#
# print(time.localtime(365*24*3600))


#结构化时间
now_time = time.localtime()
print(now_time)  # time.struct_time(tm_year=2024, tm_mon=9, tm_mday=4, tm_hour=9, tm_min=5, tm_sec=1, tm_wday=2, tm_yday=248, tm_isdst=0)

#把结构化时间转换为时间戳格式
time_stamp = time.mktime(now_time)
print(time_stamp)  # 1725411982.0

#把结构化时间转换为格式化时间
#%Y年-%m月-%d天 %X时分秒=%H时:%M分：%S秒
time_strf = time.strftime("%Y-%m-%d %X", now_time)
print(time_strf)  # 2024-09-04 09:08:26


print('='*50)

# 把格式化时间转化为结构化时间，和strftime()是逆操作
print(time.strptime(time_strf, "%Y-%m-%d %X"))   # time.struct_time(tm_year=2024, tm_mon=9, tm_mday=4, tm_hour=9, tm_min=16, tm_sec=0, tm_wday=2, tm_yday=248, tm_isdst=-1)
print(type(time.strptime(time_strf, "%Y-%m-%d %X"))) # <class 'time.struct_time'>

# 把结构化时间表示为这种形式：‘sun Jun 20 23:21:05 1993'
print(f'::::time.asctime():::::==>{time.asctime()}')  # Wed Sep  4 09:19:20 2024

# 如果参数没给或为None时，将会默认time.time()为参数。它的作用相当于time.asctime(time.localtime(secs))
print(f':::::::time.ctime()::::==>{time.ctime()}')
print(f'time.ctime(time.time())==>{time.ctime(time.time())}')




